﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;

namespace Net.DataAccess
{
	public abstract class CategoryProvider : DataAccess
	{
		static private CategoryProvider _instance = null;
		static public CategoryProvider Instance
		{
			get
			{
				if (_instance == null)
					_instance = (CategoryProvider)Activator.CreateInstance(
					   Type.GetType("Net.SqlProvider.CategorySP"));
				return _instance;
			}
		}

		public CategoryProvider()
		{
			this.ConnectionString = Globals.Settings.ConnectionString;
			this.EnableCaching = Globals.Settings.EnableCaching;
			this.CacheDuration = Globals.Settings.CacheDuration;
		}

		public abstract CategoryDetails FindByID(long id);
		public abstract int Insert(CategoryDetails obj);

		protected virtual CategoryDetails GetFromReader(IDataReader reader)
		{
			return new CategoryDetails(
				reader["TypeID"].ToString(),
				(long)reader["ID"],
				(DateTime)reader["AddedDate"],
				reader["AddedBy"].ToString(),
				reader["Name"].ToString());
		}

		protected virtual List<CategoryDetails> GetListFromReader(IDataReader reader)
		{
			List<CategoryDetails> items = new List<CategoryDetails>();
			while (reader.Read())
				items.Add(GetFromReader(reader));
			return items;
		}
	}
}